<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="__LAYUI__/layui.js"></script>
    <link href="__LAYUI__/css/layui.css" rel="stylesheet"/>
</head>
<body>
<div style="width: 100%;height: 38px">
    <button  class="layui-btn layui-btn-normal" id="backBtn" style="float: right">返回</button>
</div>

<table id="book" lay-filter="book"></table>
<table id="author" lay-filter="author" lay-data="{id: 'authorReload'}"></table>


<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-mini" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del">删除</a>
</script>

<script>
    layui.use(['table','jquery','layer'],function () {
        var table = layui.table,
            $ = layui.$,
            layer = layui.layer;;

        table.render({
            elem:'#book'
            ,cols:[[
                {field:'book_id',title:'id',width:100}
                ,{field:'book_name',title:'书名',width:200}
                ,{field:'book_company',title:'出版社',width:200}
                ,{field:'book_out_datetime',title:'计划出版时间',width:200}
                ,{field:'book_word_count',title:'字数',width:200}
                ,{field:'status',title:'书号状态',width:200},

            ]]
            ,data:[{'book_id':'{$book_id}','book_name':'{$book_name}','book_company':'{$book_company}','book_out_datetime':'{$book_out_datetime}','book_word_count':'{$book_word_count}','status':'{$status}'}]
            ,skin:'nob'

        });
        if({$user_level}=='0'){
            table.render({
                elem:'#author'
                ,height:500
                ,cols:[[
                    {field:'id',width:100}
                    ,{field:'authorPosition',width:100,}
                    ,{field:'authorName', event: 'setAuthor',style:'cursor: pointer;',width:900}
                    , {fixed: 'right', width: 160, align: 'center', toolbar: '#barDemo'}
                ]]
                ,data:[
                    {'id':'1','authorPosition':'第一主编','authorName':'{$authors.1}'}
                    ,{'id':'2','authorPosition':'第二主编','authorName':'{$authors.2}'}
                    ,{'id':'3','authorPosition':'第三主编','authorName':'{$authors.3}'}
                    ,{'id':'4','authorPosition':'第一副主编','authorName':'{$authors.4}'}
                    ,{'id':'5','authorPosition':'第二副主编','authorName':'{$authors.5}'}
                    ,{'id':'6','authorPosition':'第三副主编','authorName':'{$authors.6}'}
                    ,{'id':'7','authorPosition':'第四副主编','authorName':'{$authors.7}'}
                    ,{'id':'8','authorPosition':'第五副主编','authorName':'{$authors.8}'}
                    ,{'id':'9','authorPosition':'第六副主编','authorName':'{$authors.9}'}
                    ,{'id':'10','authorPosition':'其他','authorName':"{volist name='others' id='vo'}{$vo.author_name},{/volist}"}
                    ,{'id':'11','authorPosition':'编委','authorName':"{volist name='board' id='vo'}{$vo.author_name},{/volist}"}
                ]
                ,size:'lg'
                ,even:true
                ,id:'authorReload'
            });
        }else{
            table.render({
                elem:'#author'
                ,height:370
                ,cols:[[
                    {field:'id',width:100}
                    ,{field:'authorPosition',width:100,}
                    ,{field:'authorName', event: 'setAuthor',style:'cursor: pointer;',width:1000}
                ]]
                ,data:[
                    {'id':'1','authorPosition':'第一主编','authorName':'{$authors.1}'}
                    ,{'id':'2','authorPosition':'第二主编','authorName':'{$authors.2}'}
                    ,{'id':'3','authorPosition':'第三主编','authorName':'{$authors.3}'}
                    ,{'id':'4','authorPosition':'第一副主编','authorName':'{$authors.4}'}
                    ,{'id':'5','authorPosition':'第二副主编','authorName':'{$authors.5}'}
                    ,{'id':'6','authorPosition':'第三副主编','authorName':'{$authors.6}'}
                    ,{'id':'7','authorPosition':'第四副主编','authorName':'{$authors.7}'}
                    ,{'id':'8','authorPosition':'第五副主编','authorName':'{$authors.8}'}
                    ,{'id':'9','authorPosition':'第六副主编','authorName':'{$authors.9}'}
                    ,{'id':'10','authorPosition':'其他','authorName':"{volist name='others' id='vo'}{$vo.author_name},{/volist}"}
                    ,{'id':'11','authorPosition':'编委','authorName':"{volist name='board' id='vo'}{$vo.author_name},{/volist}"}
                ]
                ,size:'lg'
                ,even:true
                ,id:'authorReload'
            });
        }


        table.on('tool(author)', function(obj) {
            var data = obj.data;
            if (obj.event === 'setAuthor') {
                if ({$user_level} == '2') {

                } else {
                    if ((({$user_level} == '0') || (data.authorName == '')) && (data.id <= 3)) {

                        layer.open({
                            type: 2,
                            offset: '100px',
                            title: data.authorPosition,
                            scrollbar: false,
                            resize: false,
                            area: ['600px', '520px'],
                            shadeClose: true,
                            content: ['/index/input/materialEditor?author_level=' + data.id + "&book_id=" + '{$book_id}', 'no'],
                        });
                    }
                    if (data.id >= 10) {
                        layer.open({
                            type: 2,
                            offset: '100px',
                            title: data.authorPosition,
                            scrollbar: false,
                            resize: false,
                            area: ['600px', '300px'],
                            shadeClose: true,
                            content: ['/index/input/materialSubeditor?author_level=' + data.id + "&&book_id=" + '{$book_id}', 'no'],

                        });
                    }
                    if ((({$user_level} == '0') || (data.authorName == '')) && (((data.id > 3) && (data.id <= 9)))) {

                    layer.open({
                        type: 2,
                        offset: '100px',
                        title: data.authorPosition,
                        scrollbar: false,
                        resize: false,
                        area: ['600px', '300px'],
                        shadeClose: true,
                        content: ['/index/input/materialSubeditor?author_level=' + data.id + "&&book_id=" + '{$book_id}', 'no'],

                    });
                }
                }
            }

            if ((obj.event === 'del')&&(data.authorName!='')&&(data.id<10)) {

                var level = data.id;

                layer.open({
                    type:0 ,
                    content:"确认删除？",
                    yes:function (index, layero) {
                        table.reload('authorReload',{
                        });
                        $.ajax({
                            type:'post',
                            url:'/index/input/delAuthor',
                            data:{
                                'book_id':{$book_id}
                                ,'level':data.id
                            },
                            success:function (result) {
                                if(result.code){
                                    layer.msg(result.msg, {
                                        icon: 1,
                                        time: 3000 //2秒关闭（如果不配置，默认是3秒）
                                    });
                                    location.reload();
                                    layer.close(index);
                                }
                            }
                        });

                    }

                });
            }
            if ((obj.event === 'del')&&(data.authorName!='')&&(data.id>=10)){
                layer.open({
                    type: 2,
                    offset:'100px',
                    title: data.authorPosition ,
                    scrollbar: false,
                    resize: false,
                    area:['500px','380px'],
                    shadeClose: true,
                    content: ['/index/Material/manageOthers?author_level=' + data.id +'&book_id='+{$book_id},'no'],
                    end:function () {
                        location.reload();
                    }
                });
            }

            if((obj.event=='edit')&&(data.authorName!='')&&(data.id<=3)){
                layer.open({
                    type: 2,
                    offset:'100px',
                    title: data.authorPosition ,
                    scrollbar: false,
                    resize: false,
                    area:['500px','520px'],
                    shadeClose: true,
                    content: ['/index/input/editEditor?level=' + data.id +'&book_id='+{$book_id},'no'],
                    end:function () {
                        location.reload();
                    }
                });
            }
            if((obj.event=='edit')&&(data.authorName!='')&&((data.id>3)&&(data.id<=9))){
                layer.open({
                    type: 2,
                    offset:'100px',
                    title: data.authorPosition ,
                    scrollbar: false,
                    resize: false,
                    area:['500px','380px'],
                    shadeClose: true,
                    content: ['/index/input/editSubEditor?level=' + data.id +'&book_id='+{$book_id},'no'],
                    end:function () {
                        location.reload();
                    }
                });
            }
            if((obj.event=='edit')&&(data.authorName!='')&&(data.id>9)){
                layer.open({
                    type: 2,
                    offset:'100px',
                    title: data.authorPosition ,
                    scrollbar: false,
                    resize: false,
                    area:['700px','520px'],
                    shadeClose: true,
                    content: ['/index/Material/changeOthers?level=' + data.id +'&book_id='+{$book_id},'no'],
                    end:function () {
                        location.reload();
                    }
                });
            }




        });


        $(function(){
            $('#backBtn').click(function(){
                window.location.href='/index/Material';
            });
        });

    })
</script>
</body>
</html>